<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :align-center="true" :close-on-press-escape="mode != 'show' ? false : true"
             destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.name" placeholder="表名称" clearable ></el-input>
						<el-input v-model="search.comment" placeholder="表描述" clearable ></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch" ></el-button>
					</div>
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-button @click="visible = false">取 消</el-button>
						<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe height="600">
					<el-table-column type="selection" width="50"></el-table-column>
					<el-table-column label="表名称" prop="name" min-width="150" />
					<el-table-column label="表描述" prop="comment" min-width="160" />
					<el-table-column label="创建时间" prop="create_time" min-width="180" />
				</scTable>
			</el-main>
		</el-container>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	components: {
	},
	data() {
		return {
			mode: "select_data",
			titleMap: {
				select_data: '选择数据表',
			},
			visible: false,
			isSaveing: false,
			search: {
				name: '', // 表名称
				comment: '' // 表描述
			},
			apiObj: this.$API.dev_tools.code.dataTable,
			selection:[]
		}
	},
	computed: {
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode) {
			this.mode = mode;
			this.visible = true;
			return this
		},
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection.map(({ name, comment }) => ({
				name,
				comment
			}))
		},
		async submit(){
			this.isSaveing = true;
			if (!this.selection.length){
				this.$message.error('请选择数据表')
				return false
			}
			let res = await this.$API.dev_tools.code.selectTable.post({table:this.selection});
			this.isSaveing = false;
			if(res.code == 1){
				this.$emit('success', this.form, this.mode)
				this.visible = false;
				this.$message.success("操作成功")
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>


<style >
</style>

